#include <vector>

using namespace std;

class Solution {
public:
    int maxSizeSlices(vector<int>& slices) {
        vector<vector<int>> dp(slices.size() / 3, vector<int>(slices.size(), 0));
        for (int i = 0; i < slices.size(); i++) {
            dp[0][i] = slices[i];
        }
        for (int i = 1; i < slices.size() / 3; i++) {
            for (int j = 2; j < slices.size() - 1; j++) {
                for (int k = 0; k < j - 1; k++) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + slices[j]);
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < slices.size(); i++) {
            ans = max(ans, dp.back()[i]);
        }
        dp.assign(slices.size() / 3, vector<int>(slices.size(), 0));
        for (int i = 0; i < slices.size(); i++) {
            dp[0][i] = slices[i];
        }
        for (int i = 1; i < slices.size() / 3; i++) {
            for (int j = 3; j < slices.size(); j++) {
                for (int k = 1; k < j - 1; k++) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + slices[j]);
                }
            }
        }
        for (int i = 0; i < slices.size(); i++) {
            ans = max(ans, dp.back()[i]);
        }
        return ans;
    }
};